package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*
        POST  http://localhost:8080/order/submit
        {"remark":"xxxxxxxxxxxxxxxxxxx","payMethod":1,"addressBookId":"1599599207619375105"}


        服务端接收  orders 对象接收数据

        orders {"remark":"xxxxxxxxxxxxxxxxxxx","payMethod":1,"addressBookId":"1599599207619375105"}
        id  number   status:1  user_id:BaseContext获取当前线程绑定用户id  order_time: new Date()    checkout_time: 不处理
        amout:总金额 通过计算获取到的   phone:收货人   address:收货地址，通过addressBookId在地址簿表中获取
        user_name:通过user_id查询用户表  consignee:收货人姓名  通过addressBookId查询到的


        order_detail
          获取当前用户购物车中的数据 select *from shopping_cart where user_id='xxxxxx'
         List<ShoppingCart> list=xxxx;

           定义总金额
           遍历list,ShoppingCart ,创建对象，为orderDetail赋予orderId ,将ShoppingCart复制到OrderDetail，
            计算各个购物项金额累加到总
           将orderDetail加入新的集合
    */

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        //打印数据
        log.info(orders.toString());
        //调用业务层下订单功能
        orderService.submit(orders);
        //响应数据
        return R.success("下单成功");
    }
}